package com.bbs.listener;

import com.bbs.pojo.Message;
import com.bbs.pojo.dto.MessageDto;
import com.bbs.service.MessageService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageListener {
    @Autowired
    MessageService messageService;
    /**
     * 接收其他服务要发送的消息
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "message_sending_queue"),
            exchange = @Exchange(name = "message_exchange", type = ExchangeTypes.DIRECT),
            key = {"sending"}
    ))
    public void messageSendingListener(Message message){
        messageService.sendMessage(message);
    }

    /**
     * 消息删除
     */
    public void messageDeletingListener(MessageDto messageDto){

    }
}
